package com.ruoyi.gate.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gate.domain.UserMedia;
import com.ruoyi.gate.service.IUserMediaService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 媒体点位Controller
 * 
 * @author Tony
 * @date 2023-06-11
 */
@RestController
@RequestMapping("/gate/media")
public class UserMediaController extends BaseController
{
    @Autowired
    private IUserMediaService userMediaService;

    /**
     * 查询媒体点位列表
     */
    @PreAuthorize("@ss.hasPermi('gate:media:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserMedia userMedia)
    {
        startPage();
        List<UserMedia> list = userMediaService.selectUserMediaList(userMedia);
        return getDataTable(list);
    }

    /**
     * 导出媒体点位列表
     */
    @PreAuthorize("@ss.hasPermi('gate:media:export')")
    @Log(title = "媒体点位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserMedia userMedia)
    {
        List<UserMedia> list = userMediaService.selectUserMediaList(userMedia);
        ExcelUtil<UserMedia> util = new ExcelUtil<UserMedia>(UserMedia.class);
        util.exportExcel(response, list, "媒体点位数据");
    }

    /**
     * 获取媒体点位详细信息
     */
    @PreAuthorize("@ss.hasPermi('gate:media:query')")
    @GetMapping(value = "/{mediaId}")
    public AjaxResult getInfo(@PathVariable("mediaId") Long mediaId)
    {
        return success(userMediaService.selectUserMediaByMediaId(mediaId));
    }

    /**
     * 新增媒体点位
     */
    @PreAuthorize("@ss.hasPermi('gate:media:add')")
    @Log(title = "媒体点位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserMedia userMedia)
    {
        return toAjax(userMediaService.insertUserMedia(userMedia));
    }

    /**
     * 修改媒体点位
     */
    @PreAuthorize("@ss.hasPermi('gate:media:edit')")
    @Log(title = "媒体点位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserMedia userMedia)
    {
        return toAjax(userMediaService.updateUserMedia(userMedia));
    }

    /**
     * 删除媒体点位
     */
    @PreAuthorize("@ss.hasPermi('gate:media:remove')")
    @Log(title = "媒体点位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{mediaIds}")
    public AjaxResult remove(@PathVariable Long[] mediaIds)
    {
        return toAjax(userMediaService.deleteUserMediaByMediaIds(mediaIds));
    }
}
